package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strconv"
	"study5/jysp/model"
	"study5/jysp/save_data"
)




var listUrl = "http://search.jiayuan.com/v2/search_v2.php"

func main() {

	getListInfo(2)
}

func getListInfo(pageIndex int){
	formData := make(url.Values)
	formData["sex"] = []string{"f"}
	formData["stc"] = []string{"1:37,2:20.28,23:1"}
	formData["f"] = []string{"search"}
	formData["listStyle"] = []string{"bigPhoto"}
	formData["sv"] = []string{"1"}
	formData["p"] = []string{strconv.Itoa(pageIndex)}

	res,err := http.PostForm(listUrl,formData)

	if err != nil{
		fmt.Printf("get the page of %d occur err:%s\n",pageIndex,err)
		return
	}

	defer res.Body.Close()

	buf,err := ioutil.ReadAll(res.Body)

	if err != nil{
		fmt.Printf("parse the page of %d occur err:%s\n",pageIndex,err)
		return
	}

	//fmt.Println(string(buf))

	pm := new(model.PageModel)

	json.Unmarshal(buf,pm)


	saveTest(pm.UserInfo)


}

func saveTest(list []*model.ListUserInfo){
	textSaver := save_data.NewTextSaver("page1")
	textSaver.Save(list)
}
